var myChart1 = null
var myChart2 = null
var myChart3 = null
var myChart4 = null
$(document).ready(function(){
    load1()
    $(window).resize(function(){
        if (myChart1 !== null) myChart1.resize()
        if (myChart2 !== null) myChart2.resize()
        if (myChart3 !== null) myChart3.resize()
        if (myChart4 !== null) myChart4.resize()
    })
})

function load1() {
    $.ajax({
        url: service_url + '/a/zk/index/bjEnt',
        type: 'GET',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback:"success_jsonpCallback",  
        processData: false, // 告诉jQuery不要去处理发送的数据
        success: function(data) {
            if (data.status !== '00') {
                showErr("您处于未登录状态，请先登录", '1000000')
                return
            }
            load3()
            var dataList=[
                {name: '东城区', value: 0},
                {name: '西城区', value: 0},
                {name: '朝阳区', value: 0},
                {name: '丰台区', value: 0},
                {name: '石景山区', value: 0},
                {name: '海淀区', value: 0},
                {name: '门头沟区', value: 0},
                {name: '房山区', value: 0},
                {name: '通州区', value: 0},
                {name: '顺义区', value: 0},
                {name: '昌平区', value: 0},
                {name: '大兴区', value: 0},
                {name: '怀柔区', value: 0},
                {name: '平谷区', value: 0},
                {name: '密云区', value: 0},
                {name: '延庆区', value: 0}
            ]
            var resData = JSON.parse(data.data)
            var tempNum = 10
            for (var i = 0; i < resData.length; i ++) {
                for (var j = 0; j < dataList.length; j++) {
                    if (resData[i].county === dataList[j].name) {
                        dataList[j].value = resData[i].num
                        if (resData[i].num > tempNum) tempNum = resData[i].num
                    }
                }
            }

            myChart1 = echarts.init(document.getElementById('data1-main'))
            option = {
                tooltip: {
                        formatter:function(params,ticket, callback){
                            return params.name + '<br />企业数量  '+params.value+' 家'
                        }//数据格式化
                    },
                visualMap: {
                    min: 0,
                    max: tempNum,
                    left: 'left',
                    top: 'bottom',
                    text: ['高','低'],//取值范围的文字
                    inRange: {
                        color: ['#e0ffff', '#006edd']//取值范围的颜色
                    },
                    show:true//图注
                },
                geo: {
                    map: '北京',
                    roam: false,//不开启缩放和平移
                    zoom:1.23,//视角缩放比例
                    label: {
                        normal: {
                            show: true,
                            fontSize:'10',
                            color: 'rgba(0,0,0,0.7)'
                        }
                    },
                    itemStyle: {
                        normal:{
                            borderColor: 'rgba(0, 0, 0, 0.2)'
                        },
                        emphasis:{
                            areaColor: '#F3B329',//鼠标选择区域颜色
                            shadowOffsetX: 0,
                            shadowOffsetY: 0,
                            shadowBlur: 20,
                            borderWidth: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                },
                series : [
                    {
                        name: '信息量',
                        type: 'map',
                        geoIndex: 0,
                        data:dataList
                    }
                ]
            };
            myChart1.setOption(option);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            showErr("您处于未登录状态，请先登录", '1000000')
            console.log(XMLHttpRequest, textStatus, errorThrown)
        }
    })
}


function load3() {
    $.ajax({
        url: service_url + '/a/zk/index/qgEnt',
        type: 'GET',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback:"success_jsonpCallback",  
        processData: false, // 告诉jQuery不要去处理发送的数据
        success: function(data) {
            load4()
            var dataList=[
                {name:"南海诸岛",value:0},
                {name: '北京', value: 0},
                {name: '天津', value: 0},
                {name: '上海', value: 0},
                {name: '重庆', value: 0},
                {name: '河北', value: 0},
                {name: '河南', value: 0},
                {name: '云南', value: 0},
                {name: '辽宁', value: 0},
                {name: '黑龙江', value: 0},
                {name: '湖南', value: 0},
                {name: '安徽', value: 0},
                {name: '山东', value: 0},
                {name: '新疆', value: 0},
                {name: '江苏', value: 0},
                {name: '浙江', value: 0},
                {name: '江西', value: 0},
                {name: '湖北', value: 0},
                {name: '广西', value: 0},
                {name: '甘肃', value: 0},
                {name: '山西', value: 0},
                {name: '内蒙古', value: 0},
                {name: '陕西', value: 0},
                {name: '吉林', value: 0},
                {name: '福建', value: 0},
                {name: '贵州', value: 0},
                {name: '广东', value: 0},
                {name: '青海', value: 0},
                {name: '西藏', value: 0},
                {name: '四川', value: 0},
                {name: '宁夏', value: 0},
                {name: '海南', value: 0},
                {name: '台湾', value: 0},
                {name: '香港', value: 0},
                {name: '澳门', value: 0}
            ]
            var resData = JSON.parse(data.data)

            var tempNum = 10
            for (var i = 0; i < resData.length; i ++) {
                for (var j = 0; j < dataList.length; j++) {
                    if (resData[i].province.indexOf(dataList[j].name) > -1) {
                        dataList[j].value = resData[i].num
                        dataList[j].item = resData[i]
                        if (resData[i].num > tempNum) tempNum = resData[i].num
                    }
                }
            }
            // dataList完善字段
            for (var j = 0; j < dataList.length; j++) {
                var obj = dataList[j]
                if (obj.item === undefined) {
                    obj.item = {
                        num: 0,
                        fnum: 0,
                        znum: 0
                    }
                } else {
                    if (obj.item.num === undefined) obj.item.num = 0
                    if (obj.item.fnum === undefined) obj.item.fnum = 0
                    if (obj.item.znum === undefined) obj.item.znum = 0
                }

            }
            // 根据最大值设置分段数
            var per = 1
            var num1 = tempNum / 5
            if (num1 > 1) {
                per = parseInt(num1)
            }
            myChart3 = echarts.init(document.getElementById('data4-main'))
            option = {
                tooltip: {
                        formatter:function(params,ticket, callback){
                            return ' ' + params.value + ' 家企业已拓展' + params.name + '<br>共设子公司 '+params.data.item.znum+' 家<br>分公司 '+params.data.item.fnum+' 家'
                        }
                    },
                    
                visualMap: {
                    min: 0,
                    max: tempNum,
                    left: 'left',
                    top: 'bottom',
                    splitNumber: 5,
                    pieces: [
                        {max: 10},
                        {min: 10, max: 100},
                        {min: 100, max: 500},
                        {min: 500, max: 1000},
                        {min: 1000, max: 5000},
                        {min: 5000},
                    ],
                    // pieces: [
                    //     {max: per},
                    //     {min: per, max: 2*per},
                    //     {min: 2*per, max: 3*per},
                    //     {min: 3*per, max: 4*per},
                    //     {min: 4*per, max: 5*per},
                    //     {min: 5*per},
                    // ],
                    color: ['#006edd','#eac736','#e0ffff'],
                    textStyle: {
                        color: '#000000'
                    }
                },
                geo: {
                    map: 'china',
                    roam: false,//不开启缩放和平移
                    zoom:1.23,//视角缩放比例
                    label: {
                        normal: {
                            show: true,
                            fontSize:'10',
                            color: 'rgba(0,0,0,0.7)'
                        }
                    },
                    itemStyle: {
                        normal:{
                            borderColor: 'rgba(0, 0, 0, 0.2)'
                        },
                        emphasis:{
                            areaColor: '#F3B329',//鼠标选择区域颜色
                            shadowOffsetX: 0,
                            shadowOffsetY: 0,
                            shadowBlur: 20,
                            borderWidth: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                },
                series : [
                    {
                        name: '信息量',
                        type: 'map',
                        geoIndex: 0,
                        data:dataList
                    }
                ]
            };
            myChart3.setOption(option);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    })
}

function load4() {
    $.ajax({
        url: service_url + '/a/zk/index/parkEnt',
        type: 'GET',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback:"success_jsonpCallback",  
        processData: false, // 告诉jQuery不要去处理发送的数据
        success: function(data) {
            load5()
            var resData = JSON.parse(data.data)
            for (var i = 0; i < resData.length; i ++) {
                $('#data5-main .item').each(function(index,item){
                    if ($(item).text().indexOf(resData[i].park) > -1 && resData[i].park !== '') {
                        if (resData[i].park === '软件园') {
                            $(item).html(resData[i].park+'（'+resData[i].num+'）')
                        } else {
                            $(item).html(resData[i].park+'<br>（'+resData[i].num+'）')
                        }
                    }
                })
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    })
}

function load5() {
    $.ajax({
        url: service_url + '/a/zk/index/partnerEnt',
        type: 'GET',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback:"success_jsonpCallback",  
        processData: false, // 告诉jQuery不要去处理发送的数据
        success: function(data) {
            load6()
            var resData = JSON.parse(data.data)
            $('.cytzNum').text(resData.cytzNum)
            $('.kjfwNum').text(resData.kjfwNum)
            $('.kjjrNum').text(resData.kjjrNum)
            $('.tckfNum').text(resData.tckfNum)
            $('.data3-num1').text(resData.cytzNum+resData.kjfwNum+resData.kjjrNum+resData.tckfNum)
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    })
}

function load6() {
    $.ajax({
        url: service_url + '/a/zk/index/honorEnt',
        type: 'GET',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback:"success_jsonpCallback",  
        processData: false, // 告诉jQuery不要去处理发送的数据
        success: function(data) {
            load7()
            var resData = JSON.parse(data.data)
            $('#data6-main .item1>span').text(resData['国高新'])
            $('#data6-main .item2>span').text(resData['十百千'])
            $('#data6-main .item3>span').text(resData['村高新'])
            $('#data6-main .item4>span').text(resData['瞪羚'])
            $('#data6-main .item5>span').text(resData['独角兽'])
            $('#data6-main .item6>span').text(resData['全国百强'])
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    })
}

function load7() {
    console.log($('.data2-right>ul>li').width())
    $.ajax({
        url: service_url + '/a/zk/index/industryEnt',
        type: 'GET',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        contentType: 'application/json',
        dataType: 'jsonp',
        jsonpCallback:"success_jsonpCallback",  
        processData: false, // 告诉jQuery不要去处理发送的数据
        success: function(data) {
            var resData = JSON.parse(data.data)
            var sum = 0
            var maxWidth = $('.data2-right>ul>li').width() - 40
            var max = 1
            var tempArr = []
            for (var k in resData) {
                sum = sum + resData[k]
                if (resData[k] >= max) max = resData[k]
            }
            for (var k in resData) {
                tempArr[k] = resData[k] / max * 100
                if (tempArr[k] > 80) tempArr[k] = 80
            }
            $('.data2-right>ul>li:eq(0)').html('<span style="width: '+tempArr['新一代信息产业']+'%;"></span>'+resData['新一代信息产业'])
            $('.data2-right>ul>li:eq(1)').html('<span style="width: '+tempArr['人工智能']+'%;"></span>'+resData['人工智能'])
            $('.data2-right>ul>li:eq(2)').html('<span style="width: '+tempArr['生物医药']+'%;"></span>'+resData['生物医药'])
            $('.data2-right>ul>li:eq(3)').html('<span style="width: '+tempArr['医疗器械']+'%;"></span>'+resData['医疗器械'])
            $('.data2-right>ul>li:eq(4)').html('<span style="width: '+tempArr['集成电路']+'%;"></span>'+resData['集成电路'])
            $('.data2-right>ul>li:eq(5)').html('<span style="width: '+tempArr['智能制造']+'%;"></span>'+resData['智能制造'])
            $('.data2-right>ul>li:eq(6)').html('<span style="width: '+tempArr['新能源汽车']+'%;"></span>'+resData['新能源汽车'])
            $('.data2-right>ul>li:eq(7)').html('<span style="width: '+tempArr['节能环保']+'%;"></span>'+resData['节能环保'])
            $('.data2-right>ul>li:eq(8)').html('<span style="width: '+tempArr['新能源']+'%;"></span>'+resData['新能源'])
            $('.data2-right>ul>li:eq(9)').html('<span style="width: '+tempArr['新材料']+'%;"></span>'+resData['新材料'])
            $('.data2-right>ul>li:eq(10)').html('<span style="width: '+tempArr['科技服务']+'%;"></span>'+resData['科技服务'])
            
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    })
}